#include "timer.h"
#include "GetTime.h"

Timer::Timer()
{
    startTicks = 0;
    pausedTicks = 0;
    paused = false;
    started = false;
}

void Timer::start()
{
    started = true;
    paused = false;

    startTicks = RakNet::GetTime();
}

void Timer::stop()
{
    started = false;
    paused = false;
}

void Timer::pause()
{
    if((started == true) && (paused == false))
    {
        paused = true;

        pausedTicks = RakNet::GetTime() - startTicks;
    }
}

void Timer::unpause()
{
    if(paused == true)
    {
        paused = false;

        startTicks = RakNet::GetTime() - pausedTicks;

        pausedTicks = 0;
    }
}

int Timer::get_ticks()
{
    if(started == true)
    {
        if(paused == true)
        {
            return pausedTicks;
        }
        else
        {
            return RakNet::GetTime() - startTicks;
        }
    }

    return 0;
}

bool Timer::is_started()
{
    return started;
}

bool Timer::is_paused()
{
    return paused;
}
